package main

import (
	"fmt"
	"github.com/sirupsen/logrus"
	cache "monitor_serve/cache/redis"
	"monitor_serve/initialize"
	"monitor_serve/model"
	"monitor_serve/router"
	"os"
)

func main() {

	//配置文件
	initialize.InitConfig()

	initialize.InitLogrus()

	//注册数据库
	initialize.InitMySQL()

	model.Init()
	err := cache.InitRedis()
	if err != nil {
		fmt.Println(err)
	}
	//是否有这两个文件夹
	createFolder()
	//注册路由
	r := router.Router() // 使用 router 包中的函数初始化路由器
	initialize.Log.Info("Server start------")
	err = r.Run(":8080")

	if err != nil {
		logrus.Errorf("An error occurred: %v", err)
	}

}
func createFolder() {
	baseDirs := []string{"Temp", "Temp2"}

	for _, dir := range baseDirs {
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			if err := os.MkdirAll(dir, 0755); err != nil {
				initialize.Log.Errorf("Failed to create directory %s: %v", dir, err)
			} else {
				initialize.Log.Infof("Directory %s created successfully", dir)
			}
		} else {
			initialize.Log.Infof("Directory %s already exists", dir)
		}
	}
}
